// 1.退出登录
function logOut() {
    delCookie("userId");
    delCookie("userName");
    delCookie("isFull");
    delCookie("userType");
    delCookie("showMsg");
    delCookie("addCustHouseId");
    delCookie("houseId");
    delCookie("houseUser");
    delCookie("addCust");
    window.location.href = "logIndex.html";
}
// 2.空值判断
function isNull(param) {
    return param == '' || param == "" || param == null || param == undefined || param == 'null' || param == 'undefined';
}
// 3.allInfoTag=1时,返回房主的房屋使用信息,订单信息,消息信息
function getHouseUseInfo(userId, allInfoTag) {
    $("#orderlist").html("<tr><td></td><td></td><td>暂无订单</td><td></td><td></td><td></td></tr>");
    $("#noticeInfo").html("暂无公告");
    $("#repairInfo").html("暂无报修");
    $.ajax({
        url : "/HouseRent/house/getHouseUseInfo.do",
        type : "post",
        data : {
            "userId" : userId,
            "allInfoTag" : allInfoTag
        },
        dataType : "json",
        success : function(result) {
            console.log("房间使用信息查询:"+result.detail);
            if ("0000" == result.status) {
                // 房屋使用情况信息
                var useInfo = result.data.useInfo;
                $("#emptyRoom").text(useInfo.empty);
                $("#useRoom").text(useInfo.inUse);
                $("#useRatio").text(useInfo.ratio);
                $("#nearEndHouse").text(useInfo.nearEndHouse);
                if ("1" == allInfoTag) {
                    // 订单信息
                    var orderInfo = result.data.orderInfo;
                    if (!isNull(orderInfo)) {
                        $("#orderlist").html("");
                        for ( var i = 0; i < orderInfo.length; i++) {
                            var order = orderInfo[i];
                            var status = order.order_status;
                            var overDate = "";
                            if(3!=status){
                                overDate = order.nextFeeTime;
                            }
                            var tr = "<tr><td>" + order.house_number + "</td><td>" + order.user_name + "</td><td>"
                                    + order.user_tel + "</td><td>" + order.expect_end_date + "</td><td>"+overDate
                                    +"</td><td>"+ deCodeOrderStatus(status) + "</td>";
                            if (1 == status || 2 == status) {
                                tr += '<td><input type="button" class="titlebut" onclick="optOrder(this)" value="退房" />'+
                                '&nbsp;<input type="button" class="titlebut" onclick="optOrder(this)" value="收租" /></td></tr>';
                            }
                            else {
                                tr += '<td><input type="button" class="titlebut" onclick="optOrder(this)" value="删除" /></td></tr>';
                            }
                            $tr = $(tr);
                            $tr.data("orderId", order.order_id);
                            $("#orderlist").append($tr);
                        }
                    }
                    // 消息信息
                    var msgInfo = result.data.msgInfo;
                    if (!isNull(msgInfo)) {
                        $("#noticeInfo").html("");
                        $("#repairInfo").html("");
                        var hasNotice = false;
                        var hasRepair = false;
                        for ( var i = 0; i < msgInfo.length; i++) {
                            var msg = msgInfo[i];
                            var noReadTag = false;
                            if ("0" == msg.msg_type && !noReadTag) {// 消息
                                if ("0" == msg.read_tag) {// 未读消息
                                    noReadTag = true;
                                }
                            }
                            else {
                                var td = '<tr><td><span>●</span></td><td><a href="javascript:void(0)" onclick="showmsg(this)">'
                                        + msg.msg_tatile + '</a></td></tr>';
                                $td = $(td);
                                $td.data("msgContent", msg.msg_content);
                                $td.data("readTag", msg.read_tag);
                                $td.data("msgId", msg.msg_id);
                                $td.data("msgType", msg.msg_type);
                                if ("1" == msg.msg_type) {
                                    $("#noticeInfo").append($td);
                                    hasNotice = true;
                                }
                                else if ("2" == msg.msg_type) {
                                    $("#repairInfo").append($td);
                                    hasRepair=true;
                                }
                            }
                        }
                        if(!hasNotice){
                            $("#noticeInfo").html("暂无公告");
                        }
                        if(!hasRepair){
                            $("#repairInfo").html("暂无报修");
                        }
                    }
                }
            }
        },
        error : function() {
            alert("系统异常,请稍后重试!");
        }
    });
}
// 4.转码订单状态
function deCodeOrderStatus(status) {
    if (1 == status) {
        return "预定";
    }
    if (2 == status) {
        return "租住中";
    }
    if (3 == status) {
        return "已离开";
    }
    if ("预定" == status) {
        return 1;
    }
    if ("租住中" == status) {
        return 2;
    }
    if ("已离开" == status) {
        return 3;
    }
}

// 5.添加房间的图片
function addHousePic(houseId,fileElmentId,housePicId){
        var housePic = $(housePicId).val();
        if(housePic==""){
            alert("请选择房间图片!");
            return "";
        }
        $.ajaxFileUpload({
            url : "/HouseRent/house/addHousePic.do", // 需要链接到服务器地址
            secureuri : false,
            fileElementId : fileElmentId, // 文件选择框的id属性（必须）
            dataType : "json",
            success : function(result) {
                alert(result.detail);
                if(result.status=="0000"){
                    ret = result.data;
                    $(housePicId).data("houseId",ret);
                }
            },
            error:function(result){
                alert("图片上传失败,请重试");
            }
        });
}

// 6.新增房间的方法,房间ID,新增类型,需要绑定的class
function roomAddFunction(houseId,addType,addClass){
        if(isNull(houseId)){
            alert("请先上传图片");
            return;
        }
        var shi = $(addClass+" #shi").val();
        var ting = $(addClass+" #ting").val();
        var chu = $(addClass+" #chu").val();
        var wei = $(addClass+" #wei").val();
        var addressDetial = $(addClass+" #addressDetial").val();
        var houseRent = $(addClass+" #house_rent").val();
        var powerCharge = $(addClass+" #power_charge").val();
        var waterCharge = $(addClass+" #water_charge").val();
        var guarantyFee = $(addClass+" #guaranty_fee").val();
        // 默认单个新增
        var province = $(addClass+" #Select4").val();
        var city = $(addClass+" #Select5").val();
        var district = $(addClass+" #Select6").val();
        var roomNumberType="0";// 单个新增
        var roomnumber = $(addClass+" #roomnumber").val();
        var houseGoods = "";
        $('input[name="checkbox"]:checked').each(function(){
            houseGoods += $(this).val()+",";
        });
        console.log("houseGoods:"+houseGoods);
        // 批量新增
        if("moreAdd" == addType){
            province = $(addClass+" #Select1").val();
            city = $(addClass+" #Select2").val();
            district = $(addClass+" #Select3").val();
            roomNumberType=$(addClass+" #roomnumberType").val();
            if(1==roomNumberType){// 自定义类型
                roomnumber = $("#zidingyiroomnumber").val();
            }else{// 规则生成型
                roomnumber = $("#roomNumberStart").val()+","+$("#roomCount").val()+","+$("#roomSpace").val();
            }
        }

        var roomType=shi+"-"+ting+"-"+chu+"-"+wei;
        var roomAddress = province+"-"+city+"-"+district;
        $.ajax({
            url:"/HouseRent/house/addHouse.do",
            type:"post",
            data:{"houseId":houseId,"hostId":userId,"roomNubmerType":roomNumberType,"roomAddress":roomAddress,
                "roomType":roomType,"addressDetial":addressDetial,"roomnumber":roomnumber,"houseRent":houseRent,
                "powerCharge":powerCharge,"waterCharge":waterCharge,"guarantyFee":guarantyFee,
                "houseGoods":houseGoods},
            dataType:"json",
            success:function(result){
                alert(result.detail);
                if("0000"==result.status){
                    if("moreAdd" == addType){
                        clean(".moreadd");
                        $("#roompic").data("houseId","");
                    }else{
                        clean(".simadd");
                        $("#sameroompic").data("houseId","");
                    }
                    qryAllRoom();
                }
            },
            error:function(){
                alert("系统异常,请稍后重试");
                if("moreAdd" == addType){
                    clean(".moreadd");
                }else{
                    clean(".simadd");
                }
            }
        });
}

// 7.查询房主名下所有房间信息
function qryAllHouseInHostId(){
    // $("#qryAllRoomId").click(function(){
        userId = getCookie("userId");
        if(isNull(userId)){
            alert("登录状态已失效,请重新登录");
            window.location.href="logIndex.html";
        }
        $.ajax({
            url:"/HouseRent/house/qryAllHouse.do",
            type:"post",
            data:{"userId":userId},
            dataType:"json",
            success:function(result){
                console.log(result.detail);
                if(result.status=="9999"){
                    $("#allRoomList").html('<div class="roomlb">'+result.detail+'</div>');
                }else{
                    $("#allRoomList").html("");
                    var houseList = result.data;
                    for(var i=0;i<houseList.length;i++){
                        var house = houseList[i];
                        var houseStatus = "空闲";
                        // var detail = "租客入住";
                        var detail = "查看详情";
                        var user = "";
                        var userTel = "";
                        if("0"==house.can_use_tag){
                            houseStatus="使用中";
                            detail = "查看详情";
                            user = house.real_name;
                            userTel = house.link_phone;
                        }
                        var li = '<li class="bbda"><div class="roomlb"><img src="'+house.house_pic+'" id="minipic">'+
                                 '<span>房间号:</span><span>'+house.house_number+'</span><br /><span>状态:</span>'+
                                 '<span id="statu">'+houseStatus+'</span><br /> <span>入住人:</span><span>'+user+'</span><br />'+
                                 '<span>联系方式:</span><span>'+userTel+'</span><br /> <a href="Javascript:void(0)"'+
                                 'id="addcust" class="difdo" onclick="getRoomDetail(this)">'+detail+'</a></div></li>';
                        $li = $(li);
                        $li.data("houseId",house.house_id);
                        $li.data("houseUser",house.house_user_id);
                        $li.data("houseStatus",house.can_use_tag);
                        $("#allRoomList").append($li);
                    }
                }
            },
            error:function(){
                alert("系统异常,请稍后重试");
            }
        });
    // });
}

// 8.显示房间的详细信息
function getRoomDetail(a){
    var houseStatus = $(a).parent().parent().data("houseStatus");
    var houseId = $(a).parent().parent().data("houseId");
    /*
     * if("1"==houseStatus){// 登记入住 addCookie("addCustHouseId",houseId,2); cust_add(); }else{
     */
        var houseUser = $(a).parent().parent().data("houseUser");
        addCookie("houseId",houseId,2);
        addCookie("houseUser",houseUser,2);
        window.location.href="roomDetail.html";
    // }
}

// 9.转换账单状态
function deCodeAcctPayTag(tag){
    if("0"==tag){
        return "未付费";
    }else if("1"==tag){
        return "已付费";
    }else if("未付费"==tag){
        return "0";
    }else if("已付费"==tag){
        return "1";
    }
}

// 10.入住登记
function addCusts(){
    $("#addCust").click(function(){
        var houseId = getCookie("addCustHouseId");
        if(isNull(houseId)){
            alert("请先选择要入住的房间");
            return;
        }
        var userName = $("#userName").val();
        var userCertNum = $("#userCertNum").val();
        var userLinkPhone = $("#userLinkPhone").val();
        var userSex = $("#userSex").val();
        var userEmail = $("#userEmail").val();
        var userqq = $("#userqq").val();
        var useStartDate = $("#useStartDate").val();
        var useType = $("#useType").val();
        var payGuarantyFee = $("#payGuarantyFee").val();
        $.ajax({
            url:"/HouseRent/order/addCust.do",
            type:"post",
            data:{"houseId":houseId,"userName":userName,"userCertNum":userCertNum,"userLinkPhone":userLinkPhone,
                "userSex":userSex,"userEmail":userEmail,"userqq":userqq,"useStartDate":useStartDate,"useType":useType,
                "payGuarantyFee":payGuarantyFee},
            dataType:"json",
            success:function(result){
                alert(result.detail);
                if("0000"==result.status){
                    defpage();
                    $("#userName").val("");
                    $("#userCertNum").val("");
                    $("#userLinkPhone").val("");
                    $("#userSex").val("00");
                    $("#userEmail").val("");
                    $("#userqq").val("");
                    $("#useStartDate").val("");
                    $("#useType").val("00");
                    $("#payGuarantyFee").val("");
                    delCookie("addCustHouseId");// 删除cookie
                }
            },
            error:function(){
                alert("系统异常,请稍后重试");
            }
        });
    });
}

// 11.查询所有的消息
function getAllMassageInfo(userId){
    if(isNull(userId)){
        alert("登录状态已失效,请重新登录");
        logOut();
        return;
    }
    allmsg();
    // showDiv(".msgCanShowDiv","#allMsgId");
    $.ajax({
        url:"/HouseRent/msg/getAllMassageInfo.do",
        type:"post",
        data:{"userId":userId},
        dataType:"json",
        success:function(result){
            // alert(result.detail);
            if("0000"==result.status){
                $("#noReadMsgId").html("");
                $("#readMsgId").html("");
                $("#allMsgId").html("");
                var msgs = result.data;
                var hasNoRead = false;
                var hasRead = false;
                for(var i=0;i<msgs.length;i++){
                    var msg = msgs[i];
                    if("0"==msg.msg_type){
                        var msgTitle = msg.msg_content.substring(3,8)+"... ...";
                        var li = '<li><img src="img/arcicon.gif" /><a href="javascript:void(0)" onclick="showmsg(this)" id="msgtitle">'+msgTitle+'</a>'+
                                 '<span>'+msg.send_date+'</span><span>'+msg.author_name+'</span></li>';
                        var $li = $(li);
                        $li.data("msgContent",msg.msg_content);
                        $li.data("readTag",msg.read_tag);
                        $li.data("msgId",msg.msg_id);
                        $li.data("msgType",msg.msg_type);
                        var temp = '<li><img src="img/arcicon.gif" /><a href="javascript:void(0)" onclick="showmsg(this)"  id="msgtitle">'+msgTitle+'</a>'+
                                    '<span>'+msg.send_date+'</span><span>'+msg.author_name+'</span></li>';
                        var $temp = $(temp);
                        $temp.data("msgContent",msg.msg_content);
                        $temp.data("readTag",msg.read_tag);
                        $temp.data("msgId",msg.msg_id);
                        $temp.data("msgType",msg.msg_type);
                        if("0"==msg.read_tag){// 未读消息
                            hasNoRead=true;
                            $("#noReadMsgId").append($temp);
                        }else{
                            hasRead = true;
                            $("#readMsgId").append($temp);
                        }
                        console.log($temp.data("msgContent"));
                        $("#allMsgId").append($li);
                    }
                }
                if(!hasNoRead){
                    $("#noReadMsgId").html("<li>暂无消息</li>");
                }
                if(!hasRead){
                    $("#readMsgId").html("<li>暂无消息</li>");
                }
                if(!hasNoRead&&!hasRead){
                    $("#allMsgId").html("<li>暂无消息</li>");
                }
            }
        },
        error:function(){
            alert("系统异常,请稍后重试");
        }
    });
}

// 12.div的显示和隐藏
function showDiv(hideClass,showId){
    $(hideClass).hide();
    $(showId).show();
}

// 13.修改个人信息
function modifyUserInfo(){
    $("#modifyInfo").click(function(){
        console.log("修改个人信息");
        var userId = $("#modifyUserId").val();
        var linkPhone = $("#modifyLink").val();
        var realName = $("#modifyRealName").val();
        var sex = $("#modifySex").val();
        var certNum = $("#modifyCertNum").val();
        var email = $("#modifyEmail").val();
        var qq = $("#modifyqq").val();
        var fullTag = getCookie("isFull");// 放在cookie里的完善个人信息的标记
        if(isNull(fullTag)){
            fullTag = "00";// 00状态需要完善个人信息
        }
        $.ajax({
            url:"/HouseRent/login/modifyUserInfo.do",
            type:"post",
            data:{"userId":userId,"linkPhone":linkPhone,"realName":realName,
                "sex":sex,"certNum":certNum,"email":email,"qq":qq,"fullTag":fullTag},
            dataType:"json",
            success:function(result){
                alert(result.detail);
                if("0000"==result.status){
                    console.log("修改个人信息->成功");
                    $("#modifyLink").val("");
                    $("#modifyRealName").val("");
                    $("#modifySex").val("00");
                    $("#modifyCertNum").val("");
                    $("#modifyEmail").val("");
                    $("#modifyqq").val("");
                    if("00"==fullTag){
                        addCookie("isFull","01",2);
                        addCookie("userName",realName,2);
                        $("#logid").html(realName);
                    }
                }
            },
            error:function(){
                alert("系统异常,请稍后重试");
                $("#modifyLink").val("");
                $("#modifyRealName").val("");
                $("#modifySex").val("00");
                $("#modifyCertNum").val("");
                $("#modifyEmail").val("");
                $("#modifyqq").val("");
            }
        });
    });
}

// 14.修改密码
function modifyUserPwd(){
    $("#modifypwd").click(function(){
        console.log("修改密码");
        var userId = getCookie("userId");
        if(isNull(userId)){
            alert("登录状态已失效,请重新登录");
            window.location.href="logIndex.html";
        }
        var oldPwd = $("#oldPwd").val();
        var newPwd = $("#newPwd").val();
        var truePwd = $("#truePwd").val();
        if(isNull(newPwd)||isNull(truePwd)||newPwd != truePwd){
            alert("密码不能为空,或新密码输入不一致,请检查");
            return;
        }
        $.ajax({
            url:"/HouseRent/login/modifypwd.do",
            type:"post",
            data:{"userId":userId,"oldPwd":oldPwd,"newPwd":newPwd},
            dataType:"json",
            success:function(result){
                alert(result.detail);
                if("0000"==result.status){
                    logOut();
                }
            },
            error:function(){
                alert("系统异常,请稍后重试");
                $("#oldPwd").val("");
                $("#newPwd").val("");
                $("#truePwd").val("");
            }
        });
    });
}

// 15.完善个人信息
function fullUserInfo(){
    var isFull = getCookie("isFull");
    if("01"!=isFull){
        alert("请先完善个人信息");
        modifyInfo();
    }
}

// 16 发送公告
function sendMsgButFunction(){
    var userId = getCookie("userId");
    if(isNull(userId)){
        alert("登录状态已失效,请重新登录");
        window.location.href="logIndex.html";
    }
    var tatile = $("#Text1").val();
    var content = editor2.getData();
    if(isNull(tatile)){
        alert("请输入标题!");
        return;
    }
    if(isNull(content)){
        alert("请输入内容!");
        return;
    }
    var msgType="1";// 公告
    var reciver="";
    var baoxiuType = $("#baoxiuType").val();
    if(!isNull(baoxiuType)){
        var msgType="2";// 报修
        var linkPhone = $("#Text2").val();
        if(isNull(linkPhone)){
            alert("请输入联系方式");
            return;
        }
        reciver = $("#fangdong").val();
        content = baoxiuType+"<br/>&nbsp;&nbsp;"+content+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联系方式:"+linkPhone;
    }
    $.ajax({
        url:"/HouseRent/msg/sendMsg.do",
        type:"post",
        data:{"authorId":userId,"reciver":reciver,"msgType":msgType,"msgTatile":tatile,
              "msgContent":content},
        dataType:"json",
        success:function(result){
            alert(result.detail);
            if("0000"==result.status){
                $("#Text1").val("");
                editor2.setData("");
                if(msgType=="2"){
                    $("#baoxiuType").val("物品报修:");
                    $("#Text2").val("");
                }
            }
        },
        error:function(){
            alert("发送失败!请稍后重试");
        }
    });
}

// 17.查询房东下的所有住户
function qryAllUserByhostId(){
    var hostId = getCookie("userId");
    if(isNull(hostId)){
        alert("登录状态已失效,请重新登录");
        window.location.href="logIndex.html";
    }
    $.ajax({
        url:"/HouseRent/login/qryAllUserByhostId.do",
        type:"post",
        data:{"hostId":hostId},
        dataType:"json",
        success:function(result){
            console.log("17,获取房东所有被使用的房间:"+result.detail);
            if("0000"==result.status){
                var houses = result.data;
                $("#houseUseList").html("");
                for(var i=0;i<houses.length;i++){
                    var house = houses[i];
                    var li ='<li><input name="houseUser" value="'+house.house_user_id+'" class="labelauty" style="display: none;"'+
                            ' id="labelauty-'+house.house_number+'" type="checkbox"><label for="labelauty-'+house.house_number+'">'+
                            '<span class="labelauty-unchecked-image"></span>'+
                            '<span class="labelauty-unchecked" style="">房间号:'+house.house_number+'</span>'+
                            '<span class="labelauty-checked-image"></span>'+
                            '<span class="labelauty-checked">房间号:'+house.house_number+'</span></label></li>&nbsp;';
                    $("#houseUseList").append(li);
                }
            }
        },
        error:function(){
            alert("系统异常,请稍后重试");
        }
    });
}
// 18.发送者的全选和全不选
function selectAll(){
    $("#selectAll").click(function(){
        console.log($("#selectAll").is(':checked'));
        if($("#selectAll").is(':checked')){
            // $("[name='houseUser']").prop("checked","checked");// 全选
            // $("input[name='houseUser']").prop("checked");
            $("input[name='houseUser']").prop("checked", true);// 全选
        }else{
            // $("[name='houseUser']").removeAttr("checked");// 取消全选
            $("input[name='houseUser']").prop("checked", false);
        }
    });
}

// 19.发送消息
function sendMsgToAll(){
    var sender = getCookie("userId");
    if(isNull(sender)){
        alert("登录状态已失效,请重新登录");
        window.location.href="logIndex.html";
    }
    var content = editor1.getData();
    if(isNull(content)){
        alert("请填写内容!");
        return;
    }
    var reciver = "";
    $('input[name="houseUser"]:checked').each(function(){
        reciver += $(this).val()+",";
    });
    if(isNull(reciver)){
        alert("请选择接收人");
        return;
    }
    var msgType="0";// 消息
    $.ajax({
        url:"/HouseRent/msg/sendMsg.do",
        type:"post",
        data:{"authorId":sender,"reciver":reciver,"msgType":msgType,"msgTatile":"",
              "msgContent":content},
        dataType:"json",
        success:function(result){
            alert(result.detail);
            if("0000"==result.status){
                editor1.setData("");
                $("input[name='houseUser']").prop("checked", false);
            }
        }
    });
}

// 20.查询所有账单
function qryAcctInfoByTag(orderByTag){
    var userId = getCookie("userId");
    var userType = getCookie("userType");
    if (isNull(userId) || isNull(userType)) {
        alert("登录状态已失效,请重新登录");
        window.location.href = "logIndex.html";
    }
    $.ajax({
        url:"/HouseRent/acct/getAcct.do",
        type:"post",
        data:{"userId":userId,"userType":userType,"orderByTag":orderByTag},
        dataType:"json",
        success:function(result){
            // alert(result.detail);
            if("0000"==result.status){
                $("#allAcctList").html("");
                var accts = result.data;
                for(var i=0;i<accts.length;i++){
                    var acct = accts[i];
                    var tr = '<tr><td>'+acct.house_number+'</td><td>'+acct.real_name+'</td>'+
                             '<td>'+acct.link_phone+'</td><td>'+acct.start_date+'</td>'+
                             '<td>'+acct.end_date+'</td><td>'+acct.tote_fee+' 元</td><td>'+deCodeAcctPayTag(acct.pay_tag)+'</td>';
                    if("0"==acct.pay_tag && acct.order_status!=3){
                        tr+='<td><input type="button" class="titlebut" onclick="optAcct(this)" value="收租" /></td></tr>';
                    }else{
                        tr+='<td><input type="button" class="titlebut" onclick="optAcct(this)" value="删除" /></td></tr>';
                    }
                    var $tr = $(tr);
                    $tr.data("acctId",acct.acct_id);
                    $("#allAcctList").append($tr);
                }
            }else{
                $("#allAcctList").html(result.detail);
            }
        },
        error:function(){
            alert("系统异常,请稍后重试");
        }
    });
}
// 21.转换付费标记
function deCodePayTag(payTag){
    if ("0" == payTag) {
        return "未付费";
    }
    if ("1" == payTag) {
        return "已付费";
    }
    if ("未付费" == payTag) {
        return "0";
    }
    if ("已付费" == payTag) {
        return "1";
    }
}

// 22.退订房间
function endOrder(houseId){
    $.ajax({
        url:"/HouseRent/order/endOrder.do",
        type:"post",
        data:{"houseId":houseId},
        dataType:"json",
        success:function(result){
            alert(result.detail);
            var userType = getCookie("userType");
            if("01"==userType){
                logOut();
            }else{
                window.location.href="homePage.html";
            }
        },
        error:function(){
            alert("退订失败,请稍后重试");
        }
    });
}
// 23.对订单的操作
function optOrder(input){
    var optType = $(input).val();
    var orderId = $(input).parent().parent().data("orderId");
    if(isNull(orderId)){
        alert("获取订单信息失败,请重试");
        return;
    }
    $.ajax({
        url:"/HouseRent/order/optOrder.do",
        type:"post",
        data:{"orderId":orderId,"optType":optType},
        dataType:"json",
        success:function(result){
            alert(result.detail);
            if("0000"==result.status){
                defpage();// 回到首页
            }
        },
        error:function(){
            alert("系统异常,请稍后重试");
        }
    });
}

// 24.操作账单
function optAcct(input){
    var optType = $(input).val();
    var acctId = $(input).parent().parent().data("acctId");
    if(isNull(acctId)){
        alert("获取账单信息失败,请重试");
        return;
    }
    $.ajax({
        url:"/HouseRent/acct/optAcct.do",
        type:"post",
        data:{"acctId":acctId,"optType":optType},
        dataType:"json",
        success:function(result){
            alert(result.detail);
            if("0000"==result.status){
                qryAllFee();
                var userType = getCookie("userType");
                if("01"==userType){// 入住人
                    defaultPage();// 显示首页
                }
            }
        },
        error:function(){
            alert("系统异常,请稍后重试");
        }
    });
}

// 25.统计信息
function statistics(){
    // $("#exlleft").click(function(){
        var userId = getCookie("userId");
        if (isNull(userId)) {
            alert("登录状态已失效,请重新登录");
            window.location.href = "logIndex.html";
        }
        showRightDiv();
        $.ajax({
            url:"/HouseRent/acct/statistics.do",
            type:"post",
            data:{"hostId":userId},
            dataType:"json",
            success:function(result){
                if("0000"==result.status){
                    var retData = result.data;
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document
                            .getElementById('exlleft'));

                    // 指定图表的配置项和数据
                    var option = {
                        title : {
                            text : '每月收入',
                        },
                        tooltip : {},
                        legend : {
                            data : [ '房租' ],
                        },
                        xAxis : {
                            data : [ '1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月' ],
                        },
                        yAxis : {},
                        series : [ {
                            name : '房租',
                            type : 'bar',
                            data : [ retData[0], retData[1], retData[2], retData[3], retData[4], retData[5], 
                                     retData[6],retData[7], retData[8], retData[9], retData[10], retData[11]],
                        } ],
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                }
            }
        });
   // });
}

// 26.显示右边的图标
function showRightDiv(){
 // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document
            .getElementById('exlright'));
    var inUes = $("#useRoom").text();
    var empty = $("#emptyRoom").text();
    // 指定图表的配置项和数据
    option = {
        tooltip : {
            trigger : 'item',
            formatter : "{a} <br/>{b}: {c} ({d}%)"
        },
        legend : {
            orient : 'vertical',
            x : 'left',
            data : [ '已使用', '空闲']
        },
        series : [ {
            name : '入住率',
            type : 'pie',
            radius : [ '50%', '70%' ],
            avoidLabelOverlap : false,
            label : {
                normal : {
                    show : false,
                    position : 'center'
                },
                emphasis : {
                    show : true,
                    textStyle : {
                        fontSize : '30',
                        fontWeight : 'bold'
                    }
                }
            },
            labelLine : {
                normal : {
                    show : false
                }
            },
            data : [ {
                value : inUes,
                name : '已使用'
            }, {
                value : empty,
                name : '空闲'
            }]
        } ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}